//
//  ViewController.m
//  Masonry
//
//  Created by 曾泽昱 on 2024/7/12.
//

#import "ViewController.h"
#import <Masonry/Masonry.h>

@interface ViewController ()

@end

@implementation ViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    UIView *blackView = [[UIView alloc] init];
    blackView.backgroundColor = [UIColor blueColor];
    
    [self.view addSubview:blackView];
    
    [blackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.top.mas_equalTo(20);
        make.right.mas_equalTo(-20);
    }];
    
    UIView *grayView = [[UIView alloc] init];
    grayView.backgroundColor = [UIColor lightGrayColor];
    
    [self.view addSubview:grayView];
    
    [grayView mas_makeConstraints:^(MASConstraintMaker *make) {
        // 添加右、下边距约束
        make.bottom.and.right.mas_equalTo(-20);
        // 添加高度约束，让高度等于黑色view
        make.height.equalTo(blackView);
        // 添加上边距约束（上边距 = 黑色view的下边框 + 偏移量20）
        make.top.equalTo(blackView.mas_bottom).offset(20);
        // 添加左边距（左边距 = 父容器纵轴横轴中心 + 偏移量0）
        make.left.equalTo(self.view.mas_centerX).offset(0);
    }];
    
    
    
    
    
    
    
    
    
    
    
//    self.view.backgroundColor = [UIColor whiteColor];
//    UIView * view1 = [[UIView alloc] init];
//    view1.backgroundColor = [UIColor redColor];
//
//    [self.view addSubview:view1];
//
//    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.size.mas_equalTo(CGSizeMake(100, 100));
//        make.left.and.top.mas_equalTo(20);
//    }];
//
//    UIView * view2 = [[UIView alloc] init];
//    view2.backgroundColor = [UIColor lightGrayColor];
//
//    [self.view addSubview:view2];
//
//    [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
//        //大小、上边距约束与view1相同
//        make.size.and.left.mas_equalTo(view1);
//        make.top.mas_equalTo(300);
//    }];
//    
    
    
    
//    self.view.backgroundColor = [UIColor whiteColor];
//    UIView * view1 = [[UIView alloc] init];
//    view1.backgroundColor = [UIColor redColor];
//    
//    [self.view addSubview:view1];
//    
//    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.size.mas_equalTo(CGSizeMake(100, 100));
//        make.center.mas_equalTo(self.view);
//    }];
    
    
    
    
    
    
    
    
//    self.view.backgroundColor = [UIColor whiteColor];
//    // 使用Mansory布局
//    UIView *firstView = [[UIView alloc] initWithFrame:CGRectZero];
//    firstView.backgroundColor = [UIColor redColor];
//    
//    UIView * secondView = [[UIView alloc] initWithFrame:CGRectZero];
//    secondView.backgroundColor = [UIColor blueColor];
//    
//    //在做布局之前 一定要先将view建立到superView上面，否则会报错
//    [self.view addSubview:firstView];
//    [firstView addSubview:secondView];
//    
//    //添加约束，调用mas_makeConstraints，底层其实还是使用autoLayout实现的，将所需要的约束添加到block中即可
//    [firstView mas_makeConstraints: ^(MASConstraintMaker *make){
//        //设置当前视图距离父视图顶端的位置
//        make.top.mas_offset(100);
//        //设置当前视图距离父视图左端的位置
//        make.left.mas_equalTo(20);
//        //规定当前视图的宽度
//        make.width.mas_offset(250);
//        //设置当前视图的高度
//        make.height.mas_equalTo(250);
//        
//    }];
//    
//    [secondView mas_makeConstraints: ^(MASConstraintMaker *make){
//        //设置当前视图距离父视图顶端的位置
//        make.top.mas_offset(25);
//        //设置当前视图距离父视图左端的位置
////        make.left.mas_equalTo(25);
//        make.left.mas_offset(25);
//        //规定当前视图的宽度
//        make.width.mas_offset(200);
//        //设置当前视图的高度
//        make.height.mas_equalTo(200);
//        
//    }];
//    
    
    
//    UIView *superView = self.view;
//    UIView *view = [[UIView alloc] init];
//    view.translatesAutoresizingMaskIntoConstraints = NO;
//    view.backgroundColor = [UIColor greenColor];
//    [superView addSubview:view];
//    
//    UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
//    
//    [view mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(superView.mas_top).with.offset(padding.top);
//        make.left.equalTo(superView.mas_left).with.offset(padding.left);
//        make.bottom.equalTo(superView.mas_bottom).with.offset(padding.bottom);
//        make.right.equalTo(superView.mas_right).with.offset(padding.right);
//    }];
//
    
    
//    UIView *superView = self.view;
//    UIView *view = [[UIView alloc] init];
//    view.translatesAutoresizingMaskIntoConstraints = NO;
//    view.backgroundColor = [UIColor greenColor];
//    [superView addSubview:view];
//    UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
//    
//    
//    [superView addConstraints:@[
//        
//        [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeTop multiplier:1.0 constant:padding.top],
//        
//
//        [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:padding.left],
//            
//         
//        [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-padding.bottom],
//                
//        
//        [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeRight multiplier:1.0 constant:padding.top]
//
//    ]];
    
}


@end
